<!--高顺-->

<!DOCTYPE html>
<!-- suppress ThymeleafVariablesResolveInspection -->
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>忘记密码</title>

    <link type="text/css" href="/static/css/gs/wangji.css" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}" href="/static/css/bootstrap.min.css">
    <script th:src="@{/static/js/jquery-1.8.3.js}" src="/static/js/jquery-1.8.3.js"></script>
    <link rel="stylesheet" href="/static/js/gs/layui-v2.5.5/layui/css/layui.css"
          th:href="@{/static/js/gs/layui-v2.5.5/layui/css/layui.css}">
    <script th:src="@{/static/js/jquery/jquery.min.js}" src="/static/js/jquery/jquery.min.js"
            type="text/javascript"></script>
    <link th:href="@{/static/layui/css/layui.css}" href="/static/layui/css/layui.css" rel="stylesheet" media="all">
    <script th:src="@{/static/layui/layui.js}" src="/static/layui/layui.js" type="text/javascript"></script>
</head>

<style>
    #sqyy,#phonea {
        margin-top: 100px;
    }

    #tijiao {
        margin-top: 100px;
    }
    #d1,#d2,#d3,#d4,#d7,#yanzhengma{
        color: red;
        display: none;
    }
    .forget-pwd dd{
        width: 312px;
    }
</style>
<body>

<div class="content">
    <div class="web-width">
        <div class="for-liucheng">
            <div class="liulist for-cur"></div>
            <div class="liulist"></div>
            <div class="liulist"></div>
            <div class="liulist"></div>
            <div class="liutextbox">
                <div class="liutext for-cur"><em>1</em><br><strong>填写基本信息</strong></div>
                <div class="liutext for-cur"><em>2</em><br><strong>上传资质证明</strong></div>
                <div class="liutext for-cur"><em>3</em><br><strong>审核结果</strong></div>
            </div>
        </div><!--for-liucheng/-->
        <form   method="post" class="forget-pwd" enctype="multipart/form-data">
            <dl style="width: 500px">
                <dt>真实姓名：</dt>
                <dd><input type="text" id="applyRealname" name="applyRealname" onblur="zhenName()"><span id="d1"></span>
                </dd>
                <div class="clears"></div>
            </dl>
            <dl>
                <dt>讲师昵称：</dt>
                <dd><input type="text" id="applyTname" name="applyTname" onblur="nicheng()"><span id="d2"></span>
                </dd>
                <div class="clears"></div>
            </dl>
            <dl>
                <dt>邮箱：</dt>
                <dd><input type="text" id="applyEmail" name="applyEmail" onblur="mail()"><span id="d3"></span>
                </dd>
                <div class="clears"></div>
            </dl>
            <dl>
                <dt>身份证号码：</dt>
                <dd><input type="text" id="applyIdcard" name="applyIdcard" onblur="idcard()"><span id="d4"></span>
                </dd>
                <div class="clears"></div>
            </dl>
            <dl>
                <dt>自我简介：</dt>
                <dd><input type="text" id="applyIntroduction" name="applyIntroduction" style="height: 100px ;width: 300px" onblur="jianjie()"><span id="d5">简介不能超过50个字</span>
                </dd>
                <div class="clears"></div>
            </dl>
            <dl id="sqyy">
                <dt>申请原因：</dt>
                <dd><input type="text" id="applyContent" name="applyContent" style="height: 100px ;width: 300px" onblur="shenqingyuanyin()"><span id="d6">申请原因不能超过50个字</span>
                </dd>
                <div class="clears"></div>
            </dl>
            <dl id="phonea" >
                <dt>手机号：</dt>
                <dd><input type="text" id="applyPhone" name="applyPhone" onblur="onPhone()"><span id="d7"></span>
                </dd>
                <div class="clears"></div>
            </dl>
            <dl id="yz">
                <dt>验证码：</dt>
                <dd>
                    <input type="text" id="code" name="code" onblur="yanzhengmaC()">
                    <div class="yanzma">
                        <input type="button" class="btn" id="code1" value="获取验证码" onclick="codeButton()">
                    </div>
                    <br/> <span id="yanzhengma">验证码输入错误</span>
                </dd>
                <div class="clears"></div>
            </dl>
            <div class="subtijiao"><input type="button" value="提交" id="tijiao"></div>
        </form><!--forget-pwd/-->
    </div><!--web-width/-->
</div><!--content/-->


<script type="text/javascript">

    function zhenName() {
        var applyRealname=$("#applyRealname").val();
        if (applyRealname==''){
            $("#d1").css("display","inline");
            $("#d1").html("昵称不能为空");
            return false;
        }else {
            $("#d1").html("");
            return true;
        }
    }
    function nicheng() {
        var applyTname=$("#applyTname").val();
        if (applyTname==''){
            $("#d2").css("display","inline");
            $("#d2").html("昵称不能为空");
            return false;
        }else {
            $("#d2").html("");
            return true;
        }
    }
    function mail() {
        var applyEmail=$("#applyEmail").val();
        if (applyEmail==''){
            $("#d3").html("邮箱不能为空");
            $("#d3").css("display","inline");
            return false;
        } else if (!/^[\w._]+@(163)\.com(\r\n|\r|\n)?$/.test(applyEmail)){
            $("#d3").css("display","inline");
            $("#d3").html("邮箱格式错误,仅支持163邮箱");
            return false;
        }else {
            $("#d3").html("");
            return true;
        }
    }
    
    function idcard() {
        var applyIdcard=$("#applyIdcard").val();
        if (applyIdcard==''){
            $("#d4").css("display","inline");
            $("#d4").html("身份证号不能为空");
            return false;
        }else if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(applyIdcard)) {
            $("#d4").css("display","inline");
            $("#d4").html("身份证号码验证错误");
            return false;
        }else {
            $("#d4").html("");
            return true;
        }
    }

    function jianjie() {
        var applyIntroduction=$("#applyIntroduction").val();
        if (applyIntroduction==''){
            $("#d5").html("简介不能为空");
            $("#d5").css("color","red");
        }else if (applyIntroduction.length>50) {
            $("#d5").css("color","red");
            return false;
        }else {
            $("#d5").html("");
            return true;
        }
    }

    function shenqingyuanyin() {
        var applyContent=$("#applyContent").val();
        if (applyContent==''){
            $("#d6").html("申请原因不能为空");
            $("#d6").css("color","red");
            return false;
        }else if (applyContent.length>50){
            $("#d6").css("color","red");
            return false;
        }else {
            $("#d6").html("");
            return true;
        }
    }

    function onPhone() {
         var applyPhone=$("#applyPhone").val();
         if (applyPhone==''){
             $("#d7").css("display","inline");
             $("#d7").html("手机号不能为空");
             return false;
         }else if (!(/^1[3456789]\d{9}$/.test(applyPhone))){
             $("#d7").css("display","inline");
             $("#d7").html("手机号输入有误");
             return false;
         }else {
             $.ajax({
                 url:'/apply/selectHaveOrNoHave',
                 dataType:'json',
                 type:'post',
                 data:{
                     applyPhone:$("#applyPhone").val()  
                 },success:function (data) {
                        if (data.msg=="1"){
                            $("#d7").css("display","inline");
                            $("#d7").html("该手机号正在进行审核，请勿重复使用手机号！");
                            return false;
                        } else if (data.msg=="2"){
                            $("#d7").css("display","inline");
                            $("#d7").html("该手机号已经是讲师，可以直接登录");
                            return  false;
                        }else if (data.msg=="4"){
                            $("#d7").css("display","inline");
                            $("#d7").html("该手机号必须与登录手机号一致！");
                            return  false;
                        } else {
                            $("#d7").html("");
                            return true;
                        }
                 }
             })
             $("#d7").html("");
             return true;
         }
    }

    function yanzhengmaC() {
        var code=$("#code").val();
        if (code==''){
            $("#yanzhengma").css("display","inline");
            $("#yanzhengma").html("验证码不能为空");
            return false;
        }else {
            $("#yanzhengma").html("");
            return true;
        }
    }

    // 获取验证码按钮
    function codeButton() {
        var code = $("#code1");
        code.attr("disabled", "disabled");
        setTimeout(function () {
            code.css("opacity", "0.8");
        }, 100)
        var time = 60;
        var set = setInterval(function () {
            code.val("(" + --time + ")秒后重新获取");
        }, 1000);
        setTimeout(function () {
            code.attr("disabled", false).val("重新获取验证码");
            clearInterval(set);

        }, 60000);

        huyzm();
    }

    //点击获取验证码按钮后触发的事件
    var huyzm = function () {
        $.ajax({
            url: '/apply/forgetThePassword',
            type: 'post',
            dataType: 'json',
            data: {
                applyPhone: $("#applyPhone").val(),
            }, success: function () {

            }
        })
    }

    $("#tijiao").click(function () {
        if (zhenName()==true && nicheng()==true && mail()==true && idcard()==true && jianjie() ==true && shenqingyuanyin()==true && onPhone()==true && yanzhengmaC()==true){
            $.ajax({
                url:'/apply/fileUpload1',
                dataType:'json',
                type:'post',
                data:{
                    applyRealname:$("#applyRealname").val(),
                    applyContent:$("#applyContent").val(),
                    applyEmail:$("#applyEmail").val(),
                    applyIdcard:$("#applyIdcard").val(),
                    applyIntroduction: $("#applyIntroduction").val(),
                    applyTname:$("#applyTname").val(),
                    applyPhone:$("#applyPhone").val(),
                    code:$("#code").val()
                },success:function (data) {
                    var msg=data.msg;
                    console.log(msg);
                    if(msg=="提交成功"){
                        window.location.href="/apply/toApplyTeacher2";
                    }else if (msg=="提交发生了错误"){
                        alert("发生了不可预知的错误");
                    } else if (msg=="请登录"){
                        dengluzhuce();
                    }else if (msg=="验证码输入错误"){
                        $("#yanzhengma").css("display","inline");
                        $("#yanzhengma").html("验证码输入错误");
                    }
                }
            })
        } else {
            if (zhenName()==false){
                $("#d1").html("用户名不能为空");
            }
            if (nicheng()==false){
                $("#d2").html("昵称不能为空");
            }
            if (mail()==false){
                $("#d3").html("邮箱输入错误");
            }
            if (idcard()==false){
                $("#d4").html("身份证号格式有误");
            }
            if (jianjie()==false){
                $("#d5").css("color","red");
            }
            if (shenqingyuanyin()==false){
                $("#d6").css("color","red");
            }
            if (onPhone()==false){
                $("#d7").html("手机号输入有误");
            }
            if (yanzhengmaC()==false){
                $("#yanzhengma").html("验证码输入有误");
            }
        }

    });
</script>


</body>
</html>
